import time
from selenium.webdriver.common.by import By
from common.Utils import BlogDriver

#测试问卷调查编辑页面
class BlogEdit:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/survey/new?mode=survey"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)


    #正确发布问卷(登陆状态下)
    def EditSucTestByLogin(self):
        #输入问卷标题
        self.driver.find_element(By.CSS_SELECTOR,"#editorContent > div > div > div.header > div.header-content > div.sc-aXZVg.LyTMt.title.quill-container.not-focus > div > pre > div.ql-editor > p").send_keys("问卷1")
        #点击"选择题"按钮
        self.driver.find_element(By.CSS_SELECTOR,"#rc-tabs-11-panel-1 > div > div > dl:nth-child(1) > div > div:nth-child(1) > dd > div").click()
        #找到编辑区域,输入关键词
        #选择题的题目
        self.driver.find_element(By.CSS_SELECTOR,"#editorContent > div > div > div:nth-child(2) > div > div > div > div.q-content-wrap > div.q-title-wrap > div.sc-aXZVg.inUNmB.quill-container.not-focus > div > pre > div.ql-editor > p").send_keys("你最喜欢的水果是?")
        #选项1
        self.driver.find_element(By.CSS_SELECTOR,"#editorContent > div > div > div:nth-child(2) > div > div > div > div.q-content-wrap > div.q-content > div > div > div:nth-child(1) > div > div > div:nth-child(2) > div.sc-aXZVg.dDPeIT.quill-container.not-focus").send_keys("西瓜")
        #选项2
        self.driver.find_element(By.CSS_SELECTOR,"#editorContent > div > div > div:nth-child(2) > div > div > div > div.q-content-wrap > div.q-content > div > div > div:nth-child(2) > div > div > div:nth-child(2) > div.sc-aXZVg.dDPeIT.quill-container.not-focus > div > pre > div.ql-editor > p").send_keys("橙子")

        #点击"提交“按钮
        self.driver.find_element(By.CSS_SELECTOR,"#editorContent > div > div > div.footer > div.title > div > div > pre > div.ql-editor > p").click()

        #点击"提交"按钮之后出现页面的跳转,页面跳转需要加载时间,
        #可能会出现代码执行的速度比页面渲染的速度要快,导致元素查找不到
        #因此可以添加隐式等待和显示等待都可以,任选一个
        #隐式等待: 创建浏览器对象之后就可以加上,因为隐式等待的作用域在driver整个生命周期
        #显示等待: 可以作用在当前代码中



        time.sleep(3)